package de.tabuma.sso.groupprivileg;

import de.tabuma.sso.group.*;
import de.tabuma.sso.privileg.*;
import de.tabuma.sso.sso.*;
import de.tabuma.sso.user.*;
import de.tabuma.sso.useruserrelation.*;
import java.util.*;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.1.1.1.2.1 $
 * @since $Date: 2010/01/08 10:03:24 $
 */
public class GroupPrivilegWebserviceLib {

    public static void userHasPrivilegForGroupPrivileg(GroupPrivileg groupprivileg, String ssoId) throws Exception {
        SSO sso = SSOFacade.get(ssoId);
        Privileg privileg = PrivilegFacade.get(groupprivileg.getPrivilegId());
        PrivilegWebserviceLib.userHasPrivilegForPrivileg(privileg, ssoId);

        Group group = GroupFacade.get(groupprivileg.getGroupId());
        GroupWebserviceLib.userHasPrivilegForGroup(group, ssoId);
    }

    public static int userHasPrivileg(String ssoId) throws Exception {
        if(!SSOFacade.sessionIsActiv(ssoId)) {
            throw new Exception("Session has expired.");
        }

        int groupId = SSOFacade.userHasAdminGroupPrivileg(ssoId);
        if(groupId==-1) {
            throw new Exception("User has no privileg for this action.");
        }
        return groupId;
    }
}
